import * as THREE from 'three';
import Matter from "matter-js";

export class PotView {
    id: string;
    mesh: THREE.Mesh;
    body: Matter.Body;
    r: number;
    static NormalMat = new THREE.MeshBasicMaterial({ color: new THREE.Color(0xafd516) });
    static eoaMat = new THREE.MeshBasicMaterial({ color: new THREE.Color(0x66ff16) });
    static SelectedMat = new THREE.MeshBasicMaterial({ color: new THREE.Color(0xf5ab35) });

    constructor(id: string, x: number, y: number, r: number, eoa = false) {
        this.id = id;
        this.r = r;
        let geo = new THREE.SphereGeometry(this.r, 32, 32);
        this.mesh = new THREE.Mesh(geo, eoa ? PotView.eoaMat : PotView.NormalMat);
        this.body = Matter.Bodies.circle(x, y, this.r * 1.5, {mass: 1});
    }

    update() {
        let { x, y } = this.body.position;
        this.mesh.position.set(x, y, 0);
    }
}